<template>
  <div class="order-list">
    <Pane class="order-list-card">
      <span slot="title">订单管理</span>
      <section slot="content" style="width:960px">
        <!-- 搜索 -->
        <el-form size="small" :inline="true" :model="orderSearchForm" class="demo-form-inline">
          <el-row>
            <el-col :span="6">
              <el-form-item label="订单号">
                <el-input v-model="orderSearchForm.orderNo" placeholder="订单号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="收货人">
                <el-input v-model="orderSearchForm.consignee" placeholder="收货人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="手机号">
                <el-input v-model="orderSearchForm.phone" placeholder="手机号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="订单状态">
                <el-select v-model="orderSearchForm.orderState" placeholder="订单状态">
                  <el-option label="派送中" value="派送中"></el-option>
                  <el-option label="已完成" value="已完成"></el-option>
                  <el-option label="已受理" value="已受理"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="选择时间">
                <el-date-picker
                  v-model="orderSearchForm.date"
                  value-format="yyyy-mm-dd HH:MM:SS"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-button type="primary" @click="search">查询</el-button>
              <el-button type="reset" @click="reset">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
        <!-- 表格 -->
        <el-table :data="orderData" border>
          <el-table-column prop="orderNo" label="订单号" fixed width="100"></el-table-column>
          <el-table-column prop="orderTime" label="下单时间" width="200"></el-table-column>
          <el-table-column prop="phone" label="手机号" width="120"></el-table-column>
          <el-table-column prop="consignee" label="收货人" width="120"></el-table-column>
          <el-table-column prop="deliverAddress" label="配送地址" width="200"></el-table-column>
          <el-table-column prop="deliveryTime" label="送达时间" width="200"></el-table-column>
          <el-table-column prop="remarks" label="用户备注" width="120"></el-table-column>
          <el-table-column prop="orderAmount" label="订单金额" width="120"></el-table-column>
          <el-table-column prop="orderState" label="订单状态" width="120"></el-table-column>
          <el-table-column label="操作" fixed="right" width="100">
            <!-- 获取这一行数据 -->
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="handleDetail(scope.row)">查看</el-button>
              <el-button type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-- 点击查看按钮弹出详细信息 -->
        <el-dialog title="订单详情" :visible.sync="dialogVisible">
          <el-form :model="orderDetailForm">
            <el-form-item label="订单号" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.orderNo" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="下单时间" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.orderTime" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="手机号" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.phone" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="收货人" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.consignee" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="配送地址" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.deliverAddress" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="送达时间" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.deliveryTime" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="用户备注" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.remarks" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="订单金额" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.orderAmount" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="订单状态" :label-width="formLabelWidth">
              <el-input disabled v-model="orderDetailForm.orderState" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
          </div>
        </el-dialog>
        <!-- <Dialog :visible="dialogVisible" width="500" title="自定义标题" @handle-close="dialogVisible = false">
          1
        </Dialog>-->

        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[3, 6, 10]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </section>
    </Pane>
  </div>
</template>

<script>
import Pane from '@/components/Pane/Pane.vue'
// import Dialog from '@/components/Dialog/Dialog.vue'
import { getOrderList } from '@/api/order'
import moment from 'moment'
export default {
  name: 'OrderList',
  props: {},
  data() {
    return {
      orderSearchForm: {
        // 订单号
        orderNo: '',
        // 收货人
        consignee: '',
        // 手机号
        phone: '',
        // 订单状态
        orderState: '',
        date: []
      },
      // timeValueStart: [new Date(2000, 10, 10, 0, 0), new Date(2000, 10, 11, 0, 0)],
      orderData: [],
      // 查看菜单
      dialogFormVisible: false,
      // 分页当前页
      currentPage: 1,
      // 没页多少条
      pageSize: 3,
      // 总条数
      total: '',
      dialogVisible: false,
      orderDetailForm: {},
      formLabelWidth: '120px'
    }
  },
  created() {
    this.init()
  },
  methods: {
    async init() {
      const { total, data } = await getOrderList({
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        orderNo: this.orderSearchForm.orderNo,
        consignee: this.orderSearchForm.consignee,
        phone: this.orderSearchForm.phone,
        orderState: this.orderSearchForm.orderState,
        date: this.orderSearchForm.date == null ? JSON.stringify([]) : JSON.stringify(this.orderSearchForm.date)
      })
      data.forEach(v => {
        v.orderTime = moment(v.orderTime).format('YYYY-MM-DD HH:MM:SS')
        v.deliveryTime = moment(v.deliveryTime).format('YYYY-MM-DD HH:MM:SS')
      })
      this.total = total
      this.orderData = data
      console.log(this.total)
      console.log(data)
    },
    // 查看订单
    handleDetail(row) {
      this.dialogVisible = true
      // console.log(row)
      this.orderDetailForm = row
    },
    // 编辑订单
    handleEdit(row) {
      console.log(row)
      this.$router.push({
        path: '/order/order-edit',
        query: {
          id: row.id
        }
      })
    },
    // 页面显示多少条
    handleSizeChange(val) {
      this.pageSize = val
      // console.log(`每页 ${this.pageSize} 条`)
      this.init()
    },
    // 当前页
    handleCurrentChange(val) {
      this.currentPage = val
      this.init()
      // console.log(`当前页: ${this.currentPage}`)
    },
    search() {
      this.init()
    },
    reset() {
      this.orderSearchForm = {
        // 订单号
        orderNo: '',
        // 收货人
        consignee: '',
        // 手机号
        phone: '',
        // 订单状态
        orderState: '',
        date: []
      }
    }
  },
  components: {
    Pane
    // Dialog
  }
}
</script>

<style scoped>
/* .order-list >>> .el-card__body { */
/* height: 460px; */
/* } */
</style>
